﻿@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<link rel="stylesheet" href="../Scripts/kindeditor-4.1.10/themes/default/default.css" />
<script charset="utf-8" src="../Scripts/kindeditor-4.1.10/kindeditor-all.js"></script>
<script charset="utf-8" src="../Scripts/kindeditor-4.1.10/lang/zh_CN.js"></script>
<script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script>
<div class="mini-toolbar" style="padding: 2px; border-top: 0; border-left: 0; border-right: 0;">
    <table width="1000px;">
        <tr>
            <td width="1000px;">
                <a class="mini-button" id="save" name="save" iconcls="icon-save" onclick="SaveInfo" plain="true">保存</a>
                <span class="separator"></span>
                <a class="mini-button" id="close" iconcls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
            </td>
        </tr>
    </table>
</div>
<div name="DPic" id="DPic" title="广告图片" style="height: 100%; overflow: hidden;">
    <table style="width: 100%;">
        <tr>
            <td class="auto-style1" colspan="10">
                <div id="div_imglist" style="margin-left: 30px;">
                    <img id="Image0" class="ad_image" src="~/Content/Images/NoImage.jpg" data-url="" width="120" height="120"/>
                    <img id="Image1" class="ad_image" src="~/Content/Images/NoImage.jpg" data-url="" width="120" height="120"/>
                    <img id="Image2" class="ad_image" src="~/Content/Images/NoImage.jpg" data-url="" width="120" height="120"/>
                    <img id="Image3" class="ad_image" src="~/Content/Images/NoImage.jpg" data-url="" width="120" height="120"/>
                    <img id="Image4" class="ad_image" src="~/Content/Images/NoImage.jpg" data-url="" width="120" height="120"/>
                </div>
            </td>
        </tr>
        <tr>
            <td class="auto-style1" colspan="10">
                <div id="div_imglist1" style="margin-left: 30px;">
                    <img id="Image5" class="ad_image" src="~/Content/Images/NoImage.jpg" data-url="" width="120" height="120"/>
                    <img id="Image6" class="ad_image" src="~/Content/Images/NoImage.jpg" data-url="" width="120" height="120"/>
                    <img id="Image7" class="ad_image" src="~/Content/Images/NoImage.jpg" data-url="" width="120" height="120"/>
                    <img id="Image8" class="ad_image" src="~/Content/Images/NoImage.jpg" data-url="" width="120" height="120"/>
                    <img id="Image9" class="ad_image" src="~/Content/Images/NoImage.jpg" data-url="" width="120" height="120"/>
                </div>
            </td>
        </tr>
    </table>
</div>
<input type="hidden" id="FEntryID"/>
<script>

    function loaded() {
        KindEditor.ready(function (K) {
            var editor1 = K.editor({
                uploadJson: '../asp.net/upload_json.ashx?dirs=Mall&mSystemAppID=' + parent.window.getSystemAppID() + '&thumb=true',
                fileManagerJson: '../asp.net/file_manager_json.ashx?dirs=Mall&mSystemAppID=' + parent.window.getSystemAppID(),
                allowFileManager: true
            });

            $.each($("img"), function (index, e) {
                K('#' + $(e).attr("id")).click(function (K) {
                    var imgIndex = $(this).attr("id").replace("Image", "");
                    var url = $(this).attr('src');
                    if (url.toLowerCase() != "/content/images/noimage.jpg") {
                        var cfg = confirm("你确定要删除当前图片信息？");
                        if (!cfg) {
                            return;
                        }
                        else {
                            $(this).attr('src', "/content/Images/NoImage.jpg");
                            $(this).attr('data-url', "");
                            return;
                        }
                    }
                    editor1.loadPlugin('image', function () {
                        editor1.plugin.imageDialog({
                            clickFn: function (url, title, width, height, border, align) {
                                var path = ImageFilePath(url);
                                $("#Image" + imgIndex).attr('data-url', url);
                                $("#Image" + imgIndex).attr('src', path);
                                editor1.hideDialog();
                            }
                        });
                    });
                });
            });

        });
    }

    function ImageFilePath(url) {
        var result = "";
        $.ajax({
            url: "/GetItem/GetImageFilePath",
            data: { Url: url },
            type: "post",
            async: false,
            success: function (data) {
                result = data;
            },
            failure: function () {
                result = "";
            },
            error: function (jqXHR, textStatus, errorThrown) {
                return "";
            }
        });
        return result;
    }

    function SaveInfo() {
        mini.get("save").disable();
        var images = "";
        $.each($(".ad_image"), function (index, e) {
            var imageUrl = $(e).attr("data-url");
            if (imageUrl != "") {
                if (index == 0) {
                    images += imageUrl;
                } else {
                    images += "," + imageUrl;
                }
            }
        });
        var param = {
            FCorpID: parent.window.getSystemAppID(),
            FEntryID: $("#FEntryID").val(),
            FImgUrl: images
        }
        $.ajax({
            url: "/System/SaveAdvertCarouselSet",
            data: param,
            type: "post",
            dataType:"json",
            success: function (res) {
                if (res.status == 1) {
                    mini.showTips({ content: res.msg, state: "success", x: "center", y: "top", timeout: 3000 });
                } else {
                    mini.get("save").enable();
                    mini.showTips({ content: res.msg, state: "danger", x: "center", y: "top", timeout: 3000 });
                }
            }
        });
    }

    function getAdvertCarouselSet() {
        var param = {
            FCorpID: parent.window.getSystemAppID()
        }
        $.ajax({
            url: "/System/GetAdvertCarouselSet",
            data: param,
            type: "post",
            dataType:"json",
            success: function (res) {
                if (res.status == 1) {
                    $("#FEntryID").val(res.data[0].FEntryID);
                    var images = res.data[0].FImgUrl.split(",");
                    for (var i = 0; i < images.length; i++) {
                        $("#Image" + i).attr("src", res.imageUrl + images[i]);
                        $("#Image" + i).attr("data-url", images[i]);
                    }
                }
            }
        });
    }

    loaded();
    getAdvertCarouselSet();
</script>
